package  sum;
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.io.InputStream;

public class ImageUtils {
    // 绘制带透明通道的图片
    public static void drawImageWithTransparency(Graphics g, int x, int y, BufferedImage image) {
        if (image == null) return;
        Graphics2D g2d = (Graphics2D)g.create();
        try {
            g2d.drawImage(image, x, y, null);
        } finally {
            g2d.dispose();
        }
    }

    // 加载带透明通道的PNG图片
    public static BufferedImage loadPNGImage(String resourcePath) throws IOException {
        InputStream is = ImageUtils.class.getResourceAsStream(resourcePath);
        if (is == null) {
            throw new IOException("Resource not found: " + resourcePath);
        }
        try {
            return ImageIO.read(is);
        } finally {
            is.close();
        }
    }

    // 获取动画延迟
    public static int getAnimationDelay() {
        return 16; // 约60fps
    }
} 